* Import hospitalized COVID-19 cases.

/* Note: file uses highly disaggregated data.
For data privacy reasons the data is only made available in the aggregated form & the preparation is skipped */

use "$raw/goeg_hosp", clear

rename gkz municipality_id

recode municipality_id (61709 60649 60650 = 61758) /// Fladnitz an der Teichalm
	(61723 61755 = 61766) /// Weiz
	(40803 40819 = 40835) /// Peuerbach
	(60327 60336 = 60347) /// Stankt Martin im Sulmtal 
	(60607 60614 60616 60622 = 60664) /// Gratwein-Straßengel
	(41310 = 41345) /// Helfenberg in Upper Austria
	(41335 = 41346) /// St. Stefan turned to St. Stefan-Afiesl
	(41625 = 41628) /// Vorderweisenbach
	(61056 62347 = 61060) /// Merging of the municipalities of Murfeld and St. Veit in der Südsteiermark
	(61058 = 61061) // Part of Murfeld, which has now become part of the municipality of Straß in der Steiermark (due to the fact that a municipality was divided, there is a slight uncertainty here).

	
collapse (sum) norm icu, by(municipality_id year week)

foreach type in norm icu {
	bysort municipality_id: egen `type'_pre = total(`type') if year<2021
	bysort municipality_id: egen `type'_post = total(`type') if year>=2021
	bysort municipality_id (`type'_pre): replace `type'_pre = `type'_pre[1]
	bysort municipality_id (`type'_post): replace `type'_post = `type'_post[1]
	
}

recode *pre *post (.=0)

* used for aggregation
duplicates drop municipality_id, force
drop week year norm icu norm_post icu_post

save "$edited/goeg_hosp", replace
